package com.example.mall.web.controller;

import com.example.mall.domain.OrderShipments;
import com.example.mall.dto.OrderShipmentsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.OrderShipmentsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IOrderShipmentsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderShipments")
public class OrderShipmentsController {

    @Autowired
    public IOrderShipmentsService orderShipmentsService;

    /**
     * 分页查询订单物流表信息
     * @param orderShipmentsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询订单物流表信息",notes = "分页查询订单物流表信息",httpMethod = "GET")
    public JSONResult queryPage(OrderShipmentsQuery orderShipmentsQuery){
        PageDTO<OrderShipmentsDto> orderShipmentsDtoPageDTO = orderShipmentsService.queryPage(orderShipmentsQuery);
        return JSONResult.success("查询成功",orderShipmentsDtoPageDTO);
    }

    /**
     * 根据id查询订单物流表信息
     * @param shipmentId
     * @return
     */
    @GetMapping("query/{shipmentId}")
    @ApiOperation(value = "根据id查询订单物流表信息",notes = "根据id查询订单物流表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("shipmentId")Long shipmentId){
        //1.根据id查询用户信息
        if (shipmentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SHIPMENTID_NOT_ID);
        }
        OrderShipments orderShipments = orderShipmentsService.getById(shipmentId);
        return JSONResult.success("查询成功",orderShipments);
    }

    /**
     * 根据id查询订单物流表信息
     * @param shipmentId
     * @return
     */
    @GetMapping("queryOrderShipmentsById/{shipmentId}")
    @ApiOperation(value = "根据id查询订单物流表信息",notes = "根据id查询订单物流表信息",httpMethod = "GET")
    public JSONResult queryOrderShipmentsById(@PathVariable("shipmentId")Long shipmentId){
        //1.根据id查询用户信息
        if (shipmentId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SHIPMENTID_NOT_ID);
        }
        OrderShipments orderShipments = orderShipmentsService.queryOrderShipmentsById(shipmentId);
        return JSONResult.success("查询成功",orderShipments);
    }

    /**
     * 查询全部订单物流表信息
     * @param
     * @return
     */
    @GetMapping("queryOrderShipmentsList")
    @ApiOperation(value = "查询全部订单物流表信息",notes = "查询全部订单物流表信息",httpMethod = "GET")
    public JSONResult queryOrderShipmentsList(){
        List<OrderShipments> logins = orderShipmentsService.queryOrderShipmentsList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增订单物流表
     * @param orderShipmentsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增订单物流表",notes = "新增订单物流表",httpMethod = "POST")
    public JSONResult insert(@RequestBody OrderShipmentsDto orderShipmentsDto){
        orderShipmentsService.insert(orderShipmentsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改订单物流表信息
     * @param orderShipmentsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改订单物流表信息",notes = "修改订单物流表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody OrderShipmentsDto orderShipmentsDto){
        orderShipmentsService.update(orderShipmentsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除订单物流表信息
     * @param shipmentId
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除订单物流表信息",notes = "删除订单物流表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("shipmentId") Long shipmentId) {
        orderShipmentsService.delete(shipmentId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除订单物流表信息
     * @param shipmentIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除订单物流表信息",notes = "批量删除订单物流表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> shipmentIds) {
        orderShipmentsService.deleteBatch(shipmentIds);
        return JSONResult.success("批量删除成功");
    }
}
